const express = require('express');
const router = express.Router();


router.get('/', (req, res) => {
    const data = [];
    for(let i = 1; i < 10; i++)
        data.push({
            id: `${i}`,
            typeCode: `typeCode-${i}`,
            typeName: `typeName-${i}`,
            creditCode: `creditCode-${i}`,
            orderReasonCode: `orderReasonCode-${i}`,
            orderReason: `orderReason-${i}`,
            options: ['update']
        });
    res.json({
        message: '',
        payload: {
            content: data
        }
    });
});
router.get('/:id/noSubmitPart', (req, res) => {
    const content = [];
    const pageIndex = req.query.pageIndex ? parseInt(req.query.pageIndex, 10) : 0;
    const pageSize = req.query.pageSize ? parseInt(req.query.pageSize, 10) : 10;
    for(let i = 1; i <= 500; i++) content.push({
        partId: `partId${i}`,
        partCode: `partCode${i}`,
        partName: `partName${i}`,
        rowVersion: 'string'
    });
    res.json(
        {
            message: '',
            payload: {
                content: content.slice(pageIndex * pageSize, (pageIndex + 1) * pageSize),
                totalElements: 500,
            }
        }
    );
});
router.post('/import', (req, res) => {
    res.json({
        message: '导入成功'
    });
});
let time = 0;
router.put('/:id', (req, res) => {
    time += 1;
    if(time % 3)
        res.json({
            message: '编辑成功'
        });
    else
        res.status(400).send({
            message: '编辑失败，清单中已存在编号code1和code2的备件',
            payload: ['1', '2']
        });
});

module.exports = router;
